
public class Heuristics2{
	static int scoring1(NewState2 state){
		// Returns an integer, whereas the more minus the worse, the more plus the better.
		int enemyFleet = 0;
		int enemyGrowth = 0;
		int friendlyFleet = 0;
		int friendlyGrowth = 0;

		//*Eliminating double for loop make one instead
		for(Planet planet : state.Planets()){
			switch (planet.Owner()) {
			case NewState2.NEUTRAL:

				break;
			case NewState2.FRIENDLY:
				friendlyFleet += planet.NumShips();
				friendlyGrowth += planet.GrowthRate();
				break;

			default:
				enemyFleet += planet.NumShips();
				enemyGrowth += planet.GrowthRate();
				break;
			}
		}
		//		for (Planet ePlanet : state.EnemyPlanets())
		//		{
		//			enemyFleet += ePlanet.NumShips();
		//			enemyGrowth += ePlanet.GrowthRate();
		//		}
		double enemyInfo = enemyFleet + enemyGrowth * 4; 

		//		for (Planet fPlanet : state.MyPlanets())
		//		{
		//			friendlyFleet += fPlanet.NumShips();
		//			friendlyGrowth += fPlanet.GrowthRate();
		//		}
		double friendlyInfo = friendlyFleet + friendlyGrowth * 4;

		//System.err.println("Friendly: " + friendlyInfo +", Enemy: " + enemyInfo);
		if (enemyInfo == 0)
		{
			return Integer.MAX_VALUE;
		} 
		else if (friendlyInfo == 0)
		{
			return Integer.MIN_VALUE;
		}
		else
		{
			return (int)(friendlyInfo - enemyInfo);
		}
	}
	
	public static NewState2 InitialState = null;
	
	static int scoringUsingStateDepth(NewState2 state){
		// Calculate stateDepth
		int stateDepth = 1;
		NewState2 tempState = state;
		if (InitialState != null)
		{
			while (tempState.getParent() != InitialState)
			{
				tempState = tempState.getParent();
				stateDepth++;
			}
		}
		
		// Returns an integer, whereas the more minus the worse, the more plus the better.
		int enemyFleet = 0;
		int enemyGrowth = 0;
		int friendlyFleet = 0;
		int friendlyGrowth = 0;

		//*Eliminating double for loop make one instead
		for(Planet planet : state.Planets()){
			switch (planet.Owner()) {
			case NewState2.NEUTRAL:

				break;
			case NewState2.FRIENDLY:
				friendlyFleet += planet.NumShips();
				friendlyGrowth += planet.GrowthRate();
				break;

			default:
				enemyFleet += planet.NumShips();
				enemyGrowth += planet.GrowthRate();
				break;
			}
		}
		//		for (Planet ePlanet : state.EnemyPlanets())
		//		{
		//			enemyFleet += ePlanet.NumShips();
		//			enemyGrowth += ePlanet.GrowthRate();
		//		}
		double enemyInfo = enemyFleet + enemyGrowth * 4; 

		//		for (Planet fPlanet : state.MyPlanets())
		//		{
		//			friendlyFleet += fPlanet.NumShips();
		//			friendlyGrowth += fPlanet.GrowthRate();
		//		}
		double friendlyInfo = friendlyFleet + friendlyGrowth * 4;

		if (enemyInfo == 0)
		{
			return (int)(Integer.MAX_VALUE / stateDepth);
		} 
		else if (friendlyInfo == 0)
		{
			return (int)(Integer.MIN_VALUE / stateDepth);
		}
		else
		{
			return (int)((friendlyInfo - enemyInfo) / stateDepth);
		}
	}
	
	@SuppressWarnings("unused")
	static int normalizedScore(NewState2 state){
		double totalScore = 1;
		
		double ownGrowthRate = 0;
		double neutralGrowRate = 0;
		double enemyGrowthRate = 0;
		
		double neutralFleet = 0;
		double ownFleet = 0;
		double enemyFleet = 0;
		
		double ownPlanets = 0;
		double neutralPlanets = 0;
		double enemyPlanets = 0;
		
		double ownBiggestFleet = 0;
		double neutralBiggestFleet = 0;
		double enemyBiggestFleet = 0;
		
		for(Planet planet : state.Planets()){
			switch (planet.Owner()) {
			case NewState2.NEUTRAL:
				//planet.
				neutralGrowRate += planet.GrowthRate();
				neutralBiggestFleet = planet.NumShips() > neutralBiggestFleet? planet.NumShips() : neutralBiggestFleet;
				neutralFleet += planet.NumShips();
				neutralPlanets += 1;
				break;
			case NewState2.FRIENDLY:
				ownGrowthRate += planet.GrowthRate();
				ownBiggestFleet = planet.NumShips() > ownBiggestFleet? planet.NumShips() : ownBiggestFleet;
				ownFleet += planet.NumShips();
				ownPlanets += 1;
				break;

			default:
				enemyGrowthRate += planet.GrowthRate();
				
				enemyBiggestFleet = planet.NumShips() > enemyBiggestFleet? planet.NumShips() : enemyBiggestFleet;
				enemyFleet += planet.NumShips();
				enemyPlanets += 1;
				break;
			} 	
		}
		//Clustering
		
		double enemyGrowthRatePenalty = (enemyGrowthRate/ownGrowthRate)-1;
		double neutralGrowthRatePenalty = (neutralGrowRate/ownGrowthRate)-1;
		
		
		if(enemyGrowthRatePenalty < 0) totalScore *= enemyGrowthRatePenalty;
		if(neutralGrowthRatePenalty < 0 && neutralGrowthRatePenalty!= -1) totalScore *= neutralGrowthRatePenalty;
		
		
		if(enemyBiggestFleet/2 > ownBiggestFleet) totalScore *= (ownBiggestFleet/enemyBiggestFleet);
		
		if(enemyFleet > ownFleet && ownGrowthRate > enemyGrowthRate) totalScore *= ownFleet/enemyFleet * ownGrowthRate/enemyGrowthRate;
		
		/*
		 * Success scenario
		 */
		if(neutralPlanets < 2 && ownPlanets > enemyPlanets && ownFleet > enemyFleet && enemyGrowthRatePenalty < 0){
			totalScore = Integer.MAX_VALUE;
		}
		
		//********
		if(ownFleet/2 > enemyFleet && ownGrowthRate > enemyGrowthRate + neutralGrowRate) {
			totalScore *= 3;
		}
		
		//***********
		if(ownFleet/2 > enemyFleet && enemyGrowthRatePenalty < 0){
			totalScore *= 2;
		}
		
		
		/*
		 * DOOOOOOOOM SCENARIO
		 */
		//******
		if(neutralPlanets < 2 && enemyPlanets > ownPlanets && enemyFleet > ownFleet && enemyGrowthRatePenalty > 0){
			totalScore = Integer.MIN_VALUE;
		}
		
		//********
		if(enemyFleet/2 > ownFleet && enemyGrowthRate > ownGrowthRate + neutralGrowRate) {
			totalScore = Integer.MIN_VALUE;
		}
		
		//***********
		if(enemyFleet/2 > ownFleet && enemyGrowthRatePenalty > 0){
			totalScore = Integer.MIN_VALUE;
		}
		
		//System.err.println(totalScore * 100);
		
		return (int)(totalScore*100);
	}
	static int planetHeuristic(Planet planet){
		return 0;
	}
}